
#include <cstdio>
#include <BOpenGL>
#include <BPainter>
#include <BImage>
#include <BCamera>

#include <BElevation>
#include "member_BElevation.h"

using namespace BWE;

#define member					(*(member_BElevation*)_ptr)
#define member_allocate()		_ptr = new member_BElevation(this)
#define member_release()		delete (member_BElevation*)_ptr

BElevation::BElevation()
{
	member_allocate();
}
BElevation::BElevation(const BSize& size)
{
	member_allocate();
	this->setSize(size);
}
BElevation::~BElevation()
{
	member_release();
}

void BElevation::setSize(const BSize& size)
{
	if (member.size != size)
	{
		member.size = size;
		member.values = 0;
	}
}
void BElevation::setSize(int width, int height)
{
	setSize(BSize(width, height));
}
const BSize& BElevation::size() const
{
	return member.size;
}

void BElevation::setWidth(int width)
{
	BSize size(width, member.size.height());
	setSize(size);
}
int BElevation::width() const
{
	return member.size.width();
}

void BElevation::setHeight(int height)
{
	BSize size(member.size.width(), height);
	setSize(size);
}
int BElevation::height() const
{
	return member.size.height();
}

void BElevation::setValues(BFloatArray* values)
{
	member.values = values;
}
BFloatArray* BElevation::values()
{
	return member.values;
}
const BFloatArray* BElevation::values() const
{
	return member.values;
}

bool BElevation::setValue(int x, int y, float value)
{
	if (x < 0 || y < 0)
		return false;
	if (x < member.size.width() && y < member.size.height())
	{
		int index = member.size.width() * y + x;
		member.values[index] = value;
		member.dirty = true;
		return true;
	}
	return false;
}
float BElevation::value(int x, int y) const
{
	if (x < 0 || y < 0)
		return false;
	if (x < member.size.width() && y < member.size.height())
	{
		int index = member.size.width() * y + x;
		return (*member.values)[index];
	}
	return 0.0f;
}

void BElevation::clear()
{
	member.size = 0;
	member.values = 0;
}

bool BElevation::empty() const
{
	return member.values == 0 || member.size == BSize();
}




